home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 80 / CD Actual 80 Julio-Agosto 2003.iso / Linux / LinuxGazette / lg / issue24 / mirror.script < prev    next >
Encoding:
Text File  |  2002-08-14  |  3.7 KB  |  104 lines

  1. #!/bin/sh
  2. #******************************************************************
  3. #ident mirror Time-stamp: <97/09/29 13:28:44 bav>
  4. #******************************************************************
  5. #                           Gerd Bavendiek  bav@rw.sni.de  97-09-04
  6. #
  7. # Usage: mirror [-f|-verify|-floppy]
  8. #
  9. # This script tries to mirror the current working directory  on the
  10. # node "mirror". It will copy all files via rdist(1). This way a true
  11. # mirror of the current directory and its subdirectories is created.
  12. #
  13. # A remark for those, wo are not familiar with rdist(1):
  14. # In subsequent calls to the script only files, that do not exist on
  15. # node "mirror", will be copied.
  16. #
  17. # Files on "mirror", which are younger than on the actual node, will
  18. # be mentioned but remain untouched (rdist option younger)
  19. #
  20. # Remarks:
  21. # You will need an entry "mirror" in your /etc/hosts.
  22. # The files "distfile" and "Distfile" have special meaning to
  23. # rdist. If such a file is found, mirror exits immediatly.
  24. # Emacs-Backup-Files (except-pattern *~$) will not be mirrored. Watch
  25. # quoting in the here-document.
  26. #
  27. # Options:
  28. #
  29. # -f        will force removing of files on "mirror", which are 
  30. #         not on this side - this is somewhat dangerous.
  31. # -verify    just watch what would be done.
  32. #
  33. # Finally:
  34. # I sometimes want to do a quick backup of a directory using a floppy with
  35. # an ext2-Filesystem. Here cp -urvp can be used. The disadvantage of
  36. # this is handling of insufficient space on the floppy. Furthermore 
  37. # the rdist's -f option cannot be used with cp. That's why I say:
  38. #
  39. # -floppy    Haven't finished this one. Ideas welcome. Use only, if
  40. #         you are knowing, what you do ...
  41. #------------------------------------------------------------------
  42. if [ -r Distfile -o -r distfile ]; then
  43.    echo "[dD]istfile found - no action !"
  44.    exit 0
  45. fi
  46.  
  47. if [ -r .distfile ]; then
  48.    rdist -f .distfile # Gerd's special - just for personal use
  49.    exit $?
  50. fi
  51.  
  52. # Force ! Remove files on "mirror", which can not be found on this
  53. # side ! Remember: there is no "unremove" in Linux ;-)
  54. if [ "$1" = "-f" ]; then
  55.    rdist  -d PWD=`pwd` -f - << EOF
  56. ${PWD} -> mirror
  57.     install -oyounger,remove ${PWD};
  58.         except_pat ( ~\\$ );
  59. EOF
  60. # Do nothing, just watch what would be done.
  61. elif [ "$1" = "-verify" ]; then
  62.    rdist  -d PWD=`pwd` -f - << EOF
  63. ${PWD} -> mirror
  64.     install -oyounger,verify ${PWD};
  65.         except_pat ( ~\\$ );
  66.  
  67. EOF
  68. elif [ "$1" = "-floppy" ]; then
  69. # Mount floppy. Don't give up, if it's already mounted. Rely on
  70.    # RetCode 3 in this case ! You will need something like the following
  71.    # in your /etc/fstab:
  72.    # /dev/fd0            /floppy        ext2    user        0        0
  73.    mount /floppy || if [ $? -ne 3 ]; then echo "$0: mount /floppy failed !"; exit 1; fi
  74.    # If the mount hasn't succeded, don't panic: cp will totally break.
  75.    # The options: r recursive (subdir's yes), u update (copy only if
  76.    # file on /floppy is older), v verbose (tell me what you are
  77.    # doing), p preserve (preserve timestamps)
  78.    # Copying . really isn't cool.
  79.  
  80.    if [ "$2" != "-nodescend" ]; then    
  81.       DIRSIZE=`du -s . | cut -f1`    
  82.       CP_OPTIONS="-ruvp ."
  83.    else
  84.       # Shudder ! Really ugly ! Just a personal hack ! Will not handle dot-files !
  85.       DIRSIZE=`du --total -s \`find . -type f -print -maxdepth 1\` | grep total | cut -f1`
  86.       CP_OPTIONS="-uvp *"
  87.    fi
  88.  
  89.    FLOPPYSIZE=`df -k /floppy | awk 'NR==2 {print $2}'`
  90.    if [ `expr $FLOPPYSIZE \<\= $DIRSIZE` -eq 1 ]; then
  91.       echo "Insufficient space: Files will not fit on /floppy ($DIRSIZE kB needed, $FLOPPYSIZE kB avail)" 
  92.       echo "$0: exiting without copying anything !"
  93.    else    
  94.       cp $CP_OPTIONS /floppy
  95.    fi
  96.    umount /floppy || echo "$0: umount /floppy failed !"; exit 1
  97. else
  98.    rdist  -d PWD=`pwd` -f - << EOF
  99. ${PWD} -> mirror
  100.     install -oyounger ${PWD};
  101.         except_pat ( ~\\$ );
  102. EOF
  103. fi
  104.